package com.qut.atcoder.controller;

import com.qut.atcoder.mappers.QuestionMapper;
import com.qut.atcoder.pojo.Question;
import com.qut.atcoder.service.impl.QuestionServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class QuestionController {
    @Autowired(required = false)
    private QuestionMapper questionMapper;

    @Autowired(required = false)
    private QuestionServiceImpl questionService;

    //获取所有问题
    @ResponseBody
    @RequestMapping("/getQuestion")
    public List<Question> getQuestion() {
        return questionMapper.selectQuestion();
    }

    //创建题目
    //返回创建的题目编号
    @ResponseBody
    @RequestMapping("/createQuestion")
    public int createQuestion(@RequestBody Question question) {
        return questionService.createQuestion(question);
    }

    //通过id号获取题目
    @ResponseBody
    @RequestMapping("/getQuestionById")
    public List<Question> getQuestionById(@RequestBody Question question) {
        return questionService.getQuestionById(question);
    }

    //通过id删除题目
    @ResponseBody
    @RequestMapping("/deleteQuestionById")
    public int deleteQuestionById(@RequestBody Question question) {
        return questionService.deleteQuestionById(question);
    }

    //通过id来修改题目
    @ResponseBody
    @RequestMapping("/setQuestionById")
    public int setQuestionById(@RequestBody Question question) {
        return questionService.setQuestionById(question);
    }
}
